﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Recycle
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Expense_Main.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-09-04   Created by 陈天铸 V1.00.0000
    /// 功能说明：费用信息页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Expense_Main : Component.PageBase
    {
        #region ---基本变量实例化---
        Vehicle.BLL.Expense b_Expense = new Vehicle.BLL.Expense();
        Vehicle.Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string onshow;//定义没有数据时页面的显示内容
        #endregion
        #region ---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbtn_AllDelete.Attributes.Add("onClick", "return confirm('是否要删除这些记录');");
                RepeaterDataBind();//绑定数据
                Drop_News.SelectedValue = "5";
            }
        }
        /// <summary>
        /// 绑定页面Repeater数据
        /// </summary>
        protected void RepeaterDataBind()
        {
            //如果选择为全部则选择值为0 通用实体层匹配条件为1 结果为1  Drop_Select.SelectedValue == "0" ? "1": Drop_Select.SelectedValue
            this.Anp_Page.RecordCount = b_Expense.GetAllSearchCount(new Model.ComponentsInfo("Expense", "1", "1", "1", "1", "E_IsDelete", "0", "E_Time", Vehicle.Common.TextHelper.StringToDateTime((this.Gmdp_Start.DateString)), Vehicle.Common.TextHelper.StringToDateTime((this.Gmdp_End.DateString)), "E_ID"));//根据下拉菜单选择的进行数据绑定获得总数
            m_ComponentsInfo.startIndex = Anp_Page.StartRecordIndex;//当前页的起始索引
            m_ComponentsInfo.endIndex = Anp_Page.EndRecordIndex;//当前页的结束索引
            m_ComponentsInfo.Tcondition = "1"; //条件二
            m_ComponentsInfo.Tresult = "1";//匹配结果二
            m_ComponentsInfo.Scondition = "E_IsDelete";//条件三
            m_ComponentsInfo.Sresult = "0";//匹配结果三
            if (Gmdp_Start.DateString != "")//判断起始时间是否为空
            {
                m_ComponentsInfo.StartTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString);
            }
            if (Gmdp_End.DateString != "")//判断结束时间是否为空
            {
                m_ComponentsInfo.EndTime = Vehicle.Common.TextHelper.StringToDateTime(Gmdp_Start.DateString);
            }
            b_Expense.RepeaterBind(ReptShow, m_ComponentsInfo);//绑定Repeater控件
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }
        }
        /// <summary>
        /// 根据时间选择数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Select_Click(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        /// <summary>
        /// Rept激发事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                b_Expense.Delete(new Vehicle.Model.ComponentsInfo("Expense",  "E_ID", e.CommandArgument.ToString()));//删除数据
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
        }
        /// <summary>
        /// Rept绑定数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((LinkButton)(e.Item.FindControl("Lbtn_Delete"))).Attributes.Add("onClick", "return   confirm('您确定删除该记录？');");
                Label lab_C_ID = (Label)e.Item.FindControl("lab_C_ID");
                Label lab_T_ID = (Label)e.Item.FindControl("lab_T_ID");
                try
                {
                    lab_C_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Cargo", "C_ID", lab_C_ID.Text, "C_ID")).Rows[0]["C_Card"].ToString();//绑定承运单编号
                    
                }
                catch 
                {
                    lab_C_ID.Text = "无";
                }
                try
                {
                    lab_T_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", lab_T_ID.Text, "T_ID")).Rows[0]["T_Num"].ToString();//绑定任务单编号
                }
                catch
                {
                    lab_T_ID.Text = "无";
                }

            }
        }
        /// <summary>
        /// 全部删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtn_AllDelete_Click(object sender, EventArgs e)
        {
            int Count = 1;
            foreach (RepeaterItem item in ReptShow.Items)
            {
                CheckBox chk = (CheckBox)item.FindControl("Chk_Num");
                if (chk.Checked)
                {
                    Count++;
                    b_Expense.Delete(new Vehicle.Model.ComponentsInfo("Expense", "E_ID", chk.ToolTip));//删除数据
                }
            }
            if (Count > 1)
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('您还没有进行选择！')", true);
            }
        }
        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        /// <summary>
        /// 选择信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Drop_News_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (Drop_News.SelectedValue)
            {
                case "1": Response.Redirect("Admin_Main.aspx"); break;//选择用户信息页
                case "2": Response.Redirect("Motorcade_Main.aspx"); break;//选择车队信息页
                case "3": Response.Redirect("Vehicles_Main.aspx"); break;//选择车辆信息页
                case "4": Response.Redirect("Task_Main.aspx"); break;//选择任务信息页
                case "5": Response.Redirect("Expense_Main.aspx"); break;//选择费用信息页
                case "6": Response.Redirect("Pilot_Main.aspx"); break;//选择驾驶员信息页
                case "7": Response.Redirect("Cargo_Main.aspx"); break;//选择承运单信息页
            }
        }
        #endregion
    }
}
